package cn.onestoplog.currEx.common;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class FileUtils {
	public static void write2TargetFile(StringBuffer content, String targetFile) throws Exception{
		BufferedWriter out = new BufferedWriter(new FileWriter(targetFile,true));
		out.write(content.toString());
		out.flush();
		out.close();
		System.out.println("Write info into file->" + targetFile + " successfully!");
	}
	
	public static void clearDir(File dir){
		if(dir.exists() && dir.isDirectory()){
			File[] fs = dir.listFiles();
			if(null!=fs && fs.length!=0){
				for(File f:fs){
					String path = f.getAbsolutePath();
					f.deleteOnExit();
					System.out.println("File --->" + path +" has been deleted successfully!");
				}
			}
		}
	}
}
